﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace MobileControlGuru.sqlite_db
{
    public class DatabaseInitializer
    {
        private const string ResourceName = "MobileControlGuru.Resources.Task.db";

        public static void EnsureDatabaseExists(string destinationPath)
        {
            // 检查数据库文件是否存在
            if (!File.Exists(destinationPath))
            {
                // 如果不存在，从资源中提取数据库文件
                using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(ResourceName))
                {
                    if (stream == null)
                        throw new InvalidOperationException("Cannot find embedded resource.");

                    using (FileStream fileStream = File.Create(destinationPath))
                    {
                        stream.CopyTo(fileStream);
                    }
                }
            }
        }
    }
}
